package com.cashoutgaming.client.modules.shell;

import com.cashoutgaming.client.common.SessionManager;
import com.cashoutgaming.client.gin.NameTokens;
import com.cashoutgaming.client.modules.application.ApplicationPresenter;
import com.cashoutgaming.client.modules.toolbar.ApplicationToolbarPresenter;
import com.google.gwt.event.shared.GwtEvent.Type;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.HasUiHandlers;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.ContentSlot;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.gwtplatform.mvp.client.annotations.ProxyCodeSplit;
import com.gwtplatform.mvp.client.annotations.Title;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.PlaceRequest;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.gwtplatform.mvp.client.proxy.RevealContentHandler;

/**
 * This is the desktop mode presenter for the admin tool. This presenter will
 * contain all buisness logic to drive the admin tool. This presenter will
 * likely invoke other presenters / presenter widgets; e.g. customer
 * create/modify dialog
 */
public class DesktopShellPresenter extends Presenter<DesktopShellPresenter.MyView, DesktopShellPresenter.MyProxy> implements DesktopShellUiHandlers {

	// the desktop shell will have multiple slots to contain other presenters
	// for now lets have 3 slots: a main content area, a left hand side tree
	// and a dialog slot
	@ContentSlot
	public static final Type<RevealContentHandler<?>> TYPE_TOOLBAR = new Type<RevealContentHandler<?>>();
	@ContentSlot
	public static final Type<RevealContentHandler<?>> TYPE_MAINPANEL = new Type<RevealContentHandler<?>>();

	private final ApplicationToolbarPresenter applicationToolbarPresenter;

	@ProxyCodeSplit
	@NameToken(NameTokens.desktopShell)
	@Title("Desktop Application Shell")
	public interface MyProxy extends ProxyPlace<DesktopShellPresenter> {
	}

	public interface MyView extends View, HasUiHandlers<DesktopShellUiHandlers> {
	}

	@Inject
	DesktopShellPresenter(EventBus eventBus, MyView view, MyProxy proxy, ApplicationToolbarPresenter applicationToolbarPresenter, PlaceManager placeManager,
			SessionManager session) {
		super(eventBus, view, proxy, ApplicationPresenter.TYPE_SetMainContent);
		this.applicationToolbarPresenter = applicationToolbarPresenter;
		view.setUiHandlers(this);
	}

	@Override
	public void prepareFromRequest(PlaceRequest request) {
		super.prepareFromRequest(request);
	}

	@Override
	public void onBind() {
		setInSlot(TYPE_TOOLBAR, applicationToolbarPresenter);
	}

	@Override
	public void mainSlotChanged(IsWidget content) {
		// TODO we'll want to mark the selected place active on the app toolbar
		// if (content instanceof AdminDesktopPresenter) {
		// moduleDesktopNavigationPresenter.markAdminToolActive();
		// }
		// if (content instanceof UserToolDesktopPresenter) {
		// moduleDesktopNavigationPresenter.markUserToolActive();
		// }
		// if (content instanceof TaskManagerDesktopPresenter) {
		// moduleDesktopNavigationPresenter.markTaskManagerActive();
		// }
		// if (content instanceof CustomerManagerDesktopPresenter) {
		// moduleDesktopNavigationPresenter.markCustomerManagerActive();
		// }
		// if (content instanceof PartnerManagerDesktopPresenter) {
		// moduleDesktopNavigationPresenter.markPartnerManagerActive();
		// }
		// if (content instanceof LogsManagerDesktopPresenter) {
		// moduleDesktopNavigationPresenter.markLogManagerActive();
		// }
	}
}
